package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.RedBagBean;

import java.util.List;

/**
 * Created by mac on 2017/12/13.
 */

public class RedBagAdapter extends RecyclerView.Adapter<RedBagAdapter.MyViewHolder> {
    private Context context;
    private List<RedBagBean.DataBean> redbags;
    private MyViewHolder myViewHolder;
    int position;



    public RedBagAdapter(Context context, List<RedBagBean.DataBean> redbags) {
        this.context = context;
        this.redbags = redbags;
    }



    @Override
    public RedBagAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.red,parent,false);
        myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RedBagAdapter.MyViewHolder holder, int position) {

        myViewHolder.redamont.setText(redbags.get(position).getAmount()+"");
        // myViewHolder.tv_money.setText(redbags.get(position).getAmount()+"");
        myViewHolder.use_usetime.setText("使用期限: "+redbags.get(position).getStartTime()+"至"+redbags.get(position).getEndTime()+"");
        myViewHolder.red_bigcond.setText("满"+redbags.get(position).getUseCond()+"元可用(仅限优惠家商品，特价商品除外)");
        int state = redbags.get(position).getState();
        if (state == 0){
            myViewHolder.red_use.setText("立即使用");
        }else if (state == 1){
            myViewHolder.red_use.setText("已使用");
        }else {
            myViewHolder.red_use.setText("已过期");
            //   myViewHolder.red_use.setBackground(R.drawable);
        }

    }

    @Override
    public int getItemCount() {
        return redbags==null?0:redbags.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView redamont;
        TextView use_usetime;
        TextView red_bigcond;
        TextView red_use;




        public MyViewHolder(View itemView) {
            super(itemView);
            redamont = (TextView) itemView.findViewById(R.id.red_amount);
            use_usetime = (TextView) itemView.findViewById(R.id.red_usetime);
            red_bigcond = (TextView) itemView.findViewById(R.id.red_bigcond);
            red_use = (TextView) itemView.findViewById(R.id.red_use);


        }
    }


}
